package com.neusoft.bizcore.auth.converter;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.neusoft.bizcore.auth.dto.AuthContentTypeDTO;
import com.neusoft.bizcore.auth.model.AuthContentType;
import com.neusoft.bizcore.auth.repository.AuthContentTypeRepository;
import com.neusoft.bizcore.web.dto.AbstractConverter;

@Component
public class AuthContentTypeConverter extends AbstractConverter<AuthContentType, AuthContentTypeDTO> {

    @Autowired
    private AuthContentTypeRepository authContentTypeRepository;

    @Override
    public AuthContentType toModel(final AuthContentTypeDTO dto) {
        AuthContentType model;
        if (dto.isNew()) {
            model = new AuthContentType();
        } else {
            model = this.authContentTypeRepository.getOne(dto.getId());
        }
        model.setAppLabel(dto.getAppLabel());
        model.setAppName(dto.getAppName());
        return model;
    }

    @Override
    public AuthContentTypeDTO toDTO(final AuthContentType model, final boolean forListView) {
        final AuthContentTypeDTO dto = new AuthContentTypeDTO();
        dto.setId(model.getId());
        dto.setAppLabel(model.getAppLabel());
        dto.setAppName(model.getAppName());
        return dto;
    }

}
